package weather_;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author 汤舒青
 * @Version 1.0
 */


public class Client {
    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);
        Socket socket = null;
        try {
            while (true) {
                socket = new Socket(InetAddress.getLocalHost(), 9090);
                InputStream in = socket.getInputStream();
                OutputStream out = socket.getOutputStream();
                System.out.println("请输入要查询的要查询的类型（气温，风力，PM2.5,湿度）");
                String str = input.next();
                OutputStreamWriter writer = new OutputStreamWriter(out);
                writer.write(str);
                writer.write("\n");
                writer.flush();
                if (str.equals("exit")) {
                    return;
                }
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                String str1 = null;
                while ((str1 = reader.readLine()) != null) {
                    System.out.println(str1);
                }
                socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            socket.close();


        }

    }
}
